package com.wxzz.elearing.user.api.admin;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.user.dto.EnterpriseDto;
import com.wxzz.elearing.user.dto.EnterpriseInsDto;
import com.wxzz.elearing.user.dto.EnterpriseUpdateLogDto;
import com.wxzz.elearing.user.dto.EnterpriseUpdateWxUserDto;
import com.wxzz.elearing.user.entity.CommonCategory;
import com.wxzz.elearing.user.entity.Enterprise;
import com.wxzz.elearing.user.entity.EnterpriseUpdateLog;
import com.wxzz.elearing.user.service.IEnterpriseService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 企业 前端控制器
 * </p>
 *
 * @author
 * @since 2021-04-01
 */
@RestController
@RequestMapping("/enterprise")
@Api(tags = "企业接口(后台)")
public class EnterpriseController {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Autowired
    private IEnterpriseService enterpriseService;

    @ApiOperation(value = " 总后台新增企业(总后台)", notes = " 总后台新增企业(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "saveEnterprise", method = RequestMethod.POST)
    public ReturnVO saveEnterprise(@RequestBody Enterprise enterprise) {
        return enterpriseService.saveEnterprise(enterprise);
    }

    @ApiOperation(value = " 修改企业(总后台)", notes = " 修改企业(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "updateEnterprise", method = RequestMethod.POST)
    public ReturnVO updateEnterprise(@RequestHeader String token,@RequestBody Enterprise enterprise) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return enterpriseService.updateEnterprise(jsonObject,enterprise);
    }

    @ApiOperation(value = " 企业列表(总后台)", notes = " 企业列表(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "listEnterprise", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<Enterprise>>> listEnterprise(HttpServletResponse response, @RequestBody EnterpriseDto enterpriseDto) {
        return enterpriseService.listEnterprise(response,enterpriseDto);
    }

    @ApiOperation(value = " 企业详情(总后台)", notes = " 企业详情(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "selectEnterpriseById/{enterpriseId}", method = RequestMethod.POST)
    public ReturnVO<Enterprise> selectEnterpriseDetail(@PathVariable Long enterpriseId) {
        return enterpriseService.selectEnterpriseDetail(enterpriseId);
    }

    @ApiOperation(value = " 企业操作列表(总后台)", notes = " 企业操作列表(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "listEnterpriseUpdateLog", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<EnterpriseUpdateLog>>> listEnterpriseUpdateLog(@Valid @RequestBody EnterpriseUpdateLogDto enterpriseUpdateLogDto) {
        return enterpriseService.listEnterpriseUpdateLog(enterpriseUpdateLogDto);
    }

    @ApiOperation(value = " 企业改绑短信发送(后台)", notes = " 企业改绑短信发送(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "sendCode/{enterpriseId}", method = RequestMethod.POST)
    public ReturnVO sendCode(@PathVariable Long enterpriseId) {
        return enterpriseService.sendCode(enterpriseId);
    }

    @ApiOperation(value = " 企业改绑院长(后台)", notes = " 企业改绑院长(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "enterpriseUpdateWxUser", method = RequestMethod.POST)
    public ReturnVO enterpriseUpdateWxUser(@RequestHeader String token,@RequestBody EnterpriseUpdateWxUserDto enterpriseUpdateWxUserDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return enterpriseService.enterpriseUpdateWxUser(jsonObject.getLong("enterpriseId"),enterpriseUpdateWxUserDto);
    }
}
